home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DATABASE / BORUSR2.ZIP;1 / PICKLIST.PRG < prev    next >
Encoding:
Text File  |  1992-06-03  |  13.9 KB  |  463 lines

  1. PROCEDURE PickList
  2. *--------------------------------------------------------------------------
  3. *-- Programmer..: Martin Leon (HMAN) (A-T)
  4. *-- Date........: 11/1990
  5. *-- Notes.......: A "generic" PickList routine ...
  6. *-- Written for.: dBASE IV, 1.1
  7. *-- Rev. History: Published in TechNotes, November, 1990 (DIYPOPUP)
  8. *--               Modified for dHUNG/dUFLP standards, Ken Mayer, 7/12/91
  9. *-- Calls.......: None
  10. *-- Called by...: Any
  11. *-- Usage.......: do PickList with "<cFields>",<nULRow>,<nULCol>,<nBRRow>,;
  12. *--                <nBRCol>, "<cNormColor>","<cFieldColor>","<cBorder>"
  13. *-- Example.....: Do PickList with "First_name+' '+Last_name",5,10,15,60,;
  14. *--                "rg+/gb","gb/r","DOUBLE"
  15. *-- Returns.....: indirectly returns the record pointer of record that was
  16. *--                 highlighted when <Enter> was pressed.
  17. *-- Parameters..: cFields     = fields to be displayed in picklist
  18. *--               nULRow      = Row coordinate of upper left corner
  19. *--               nULCol      = Column coordinate of upper left corner
  20. *--               nBRRow      = Row coordinate of lower right corner
  21. *--               nBRCol      = Column coordinate of lower right corner
  22. *--               cNormColor  = Foreground/Background of normal text
  23. *--               cFieldColor = Foreground/Background of highlighted fields
  24. *--               cBorder     = NONE, SINGLE, DOUBLE (defaults to Single if
  25. *--                               sent as a nul string ("") )
  26. *--------------------------------------------------------------------------
  27.     parameter cFields, nULRow, nULCol, nBRRow, nBRCol, cNormColor, ;
  28.             cFieldColor, cBorder
  29.  
  30.     private cCursor, cEscape, cTalk
  31.     
  32.     cCursor = set("CURSOR")
  33.     cEscape = set("ESCAPE")
  34.     cTalk   = set("TALK")
  35.     set cursor off
  36.     set escape off
  37.     set talk off
  38.     cTypeCheck = type("cFields")+type("nULRow")+type("nULCol")+type("nBRRow")+ ;
  39.         type("nBRCol")+type("cNormColor")+type("cFieldColor")+type("cBorder")
  40.  
  41.     lError = .F.
  42.     do case
  43.         && Check data types
  44.         case cTypeCheck # "CNNNNCCC"
  45.             clear
  46.             @ 7,17 say "Data type mismatch -- check all parameters"
  47.             lError = .T.
  48.         
  49.         && Check for bottom limit with STatUS ON
  50.         case ((nBRRow >21 .and. set("DISPLAY") # "EGA43")    ;
  51.                 .or. (nBRRow >39 .and. set("DISPLAY") = "EGA43")) ;
  52.                 .and. set("STatUS") = "ON"
  53.             clear
  54.             @ 7,15 say "Cannot use this popup on or below STatUS line"
  55.             lError = .T.
  56.         
  57.         && Check for bottom limit with STatUS ofF
  58.         case ((nBRRow >24 .and. set("DISPLAY") # "EGA43")    ;
  59.                 .or. (nBRRow >42 .and. set("DISPLAY") = "EGA43")) ;
  60.                 .and. set("STatUS") = "ofF"
  61.             clear
  62.             @ 7,16 say "Bottom coordinate beyond bottom of screen"
  63.             lError = .T.
  64.         
  65.         && Check left & right coordinates
  66.         case nULCol < 0 .or. nBRCol > 79
  67.             clear
  68.             @ 7,24 say "Invalid Column coordinate"
  69.             lError = .T.
  70.     
  71.         && Check to make sure popup can display at least one record
  72.         case nBRRow - nULRow < 2
  73.             clear
  74.             @ 7,19 say "Popup must be at least 3 lines high"
  75.             lError = .T.
  76.         
  77.     endcase
  78.  
  79.     if lError
  80.         @ 5,5 to 9,70 double
  81.         @ 11, 32 say "Press Any Key"
  82.         nX = 0
  83.         do while nX = 0
  84.             nX = inkey()
  85.         enddo
  86.         set cursor &cCursor
  87.         set escape &cEscape
  88.         set talk &cTalk
  89.         return
  90.     endif
  91.  
  92.     && Save colors of normal and fields to restor when done
  93.     cFieldset = set("ATTRIBUTES")
  94.     cNormSet = left(cFieldset, at(",",cFieldset)-1)
  95.     do while "," $ cFieldset
  96.         cFieldset = substr(cFieldset, at(",",cFieldset)+1)
  97.     enddo
  98.  
  99.     && If they were provided, set to colors passed on from calling program
  100.     if len(cNormColor) # 0
  101.         set color of normal to &cNormColor
  102.     endif
  103.     if len(cFieldColor) # 0
  104.         set color of fields to &cFieldColor
  105.     endif
  106.  
  107.     nPromptW = nBRCol - nULCol - 1
  108.     @ nULRow, nULCol clear to nBRRow, nBRCol 
  109.     @ nULRow, nULCol to nBRRow, nBRCol &cBorder
  110.  
  111.     if eof()
  112.        skip -1
  113.     endif
  114.  
  115.     && Save current record pointer and determine record number of top record
  116.     nTmpRec = recno()
  117.     go top
  118.     nTopRec = recno()
  119.     go nTmpRec
  120.     nMaxRecs = nBRRow - nULRow - 1
  121.     nKey = 0
  122.     lGoBack = .F.
  123.     declare aPrompt[nMaxRecs], aRec[nMaxRecs]
  124.  
  125.     do while .not. lGoBack
  126.         nChcNum = 1
  127.         nTopRow = nULRow + 1
  128.         nLeftCol = nULCol + 1
  129.         nRowOffset = 0
  130.         nLastCurs = 0
  131.  
  132.         && This loop puts text into prompts
  133.         do while nRowOffset + 1 <= nMaxRecs
  134.             if .not. eof()
  135.                 cTemp = &cFields        && Expands cFields into string expression
  136.                 aPrompt[nChcNum] = substr(cTemp, 1, nPromptW)
  137.             
  138.                 && If prompt doesn't fill entire box, add spaces
  139.                 if len(aPrompt[nChcNum]) < nPromptW
  140.                     aPrompt[nChcNum] = aPrompt[nChcNum] + ;
  141.                         space(nPromptW - len(aPrompt[nChcNum]))
  142.                 endif
  143.  
  144.                 aRec[nChcNum] = recno()
  145.                 @ nTopRow+nRowOffset , nLeftCol say aPrompt[nChcNum]
  146.             endif
  147.             nRowOffset = nRowOffset + 1
  148.             nChcNum = nChcNum + 1
  149.             skip
  150.         
  151.             && If last record reached, clear rest of box
  152.             if eof()
  153.                 do while nRowOffset + 1 <= nMaxRecs
  154.                     @ nTopRow+nRowOffset, nLeftCol say space(nPromptW)
  155.                     nRowOffset = nRowOffset +1
  156.                 enddo
  157.                 exit
  158.             endif
  159.         enddo
  160.     
  161.         nHighChc = nChcNum - 1
  162.         if nKey # 2 .and. nKey # 3   && if the last key pressed wasn't <end>
  163.             nChcNum = 1               && or <PgDn>
  164.             nRowOffset = 0
  165.         else
  166.             nChcNum = nHighChc
  167.             nRowOffset = nHighChc - 1
  168.         endif
  169.     
  170.         @ nTopRow+nRowOffset , nLeftCol get aPrompt[nChcNum]
  171.         clear gets
  172.     
  173.         && This loops traps the keys
  174.         do while .T.
  175.             nKey = inkey()
  176.             do case
  177.         
  178.                 case nKey = 5   && Up arrow
  179.                 
  180.                     && If first record displayed is first record in database
  181.                     && and it is already highlighted
  182.                     if aRec[1] = nTopRec .and. nChcNum = 1
  183.                         loop
  184.                     endif
  185.                 
  186.                     && If first record is highlighted but is not top record,
  187.                     && shift prompt contents down
  188.                     if aRec[1] # nTopRec .and. nChcNum = 1
  189.                         go aRec[1]
  190.                         nX = nHighChc 
  191.                         do while nX > 1
  192.                             aRec[nX] = aRec[nX - 1]
  193.                             aPrompt[nX] = aPrompt[nX - 1]
  194.                             nX = nX - 1
  195.                         enddo
  196.                     
  197.                         && Get prompt for additional record to be displayed
  198.                         skip -1
  199.                         aRec[1] = recno()
  200.                         cTemp = &cFields
  201.                         aPrompt[1] = substr(cTemp, 1, nPromptW)
  202.                         if len(aPrompt[1]) < nPromptW
  203.                             aPrompt[1] = aPrompt[1] + ;
  204.                                 space(nPromptW - len(aPrompt[1]))
  205.                         endif
  206.                         skip + nMaxRecs
  207.                     
  208.                         && If maximum possible records aren't displayed
  209.                         if nHighChc < nMaxRecs
  210.                             nHighChc = nHighChc + 1
  211.                             skip -1
  212.                             aRec[nHighChc] = recno()
  213.                             cTemp = &cFields
  214.                             aPrompt[nHighChc] = substr(cTemp, 1, nPromptW)
  215.                             if len(aPrompt[nHighChc]) < nPromptW
  216.                                 aPrompt[nHighChc] = aPrompt[nHighChc] + ;
  217.                                 space(nPromptW - len(aPrompt[nHighChc]))
  218.                             endif
  219.                             skip
  220.                         endif
  221.                     
  222.                         && Redisplay prompts with new contents
  223.                         nX = 1
  224.                         do while nX < nHighChc + 1
  225.                             @ nTopRow + nX - 1, nLeftCol say aPrompt[nX]
  226.                             nX = nX + 1
  227.                         enddo
  228.                         nChcNum = 2
  229.                     endif
  230.                 
  231.                    nChcNum = iif(nChcNum = 1, nHighChc, nChcNum - 1)
  232.                    nRowOffset = iif(nChcNum = 1, 0, nChcNum - 1)
  233.                    nLastOne = iif(nChcNum = nHighChc, 1, nChcNum+1)
  234.                    nThisOne = nChcNum
  235.  
  236.                    @ nTopRow+iif(nChcNum = nHighChc, 0, nRowOffset+1) , ;
  237.                       nLeftCol say aPrompt[nLastOne]
  238.                    @ nTopRow+nRowOffset , nLeftCol get aPrompt[nThisOne]
  239.                    clear gets
  240.  
  241.                 case nKey = 24   && Dn arrow
  242.                 
  243.                     && If last prompt is highlighted and it is last record
  244.                     if eof() .and. nChcNum = nHighChc
  245.                         loop
  246.                     endif
  247.                 
  248.                     && If not at last record and bottom prompt is highlighted,
  249.                     && shift prompt contents up
  250.                     if .not. eof() .and. nChcNum = nHighChc
  251.                         nX = 1
  252.                         do while nX < nMaxRecs
  253.                             aRec[nX] = aRec[nX + 1]
  254.                             aPrompt[nX] = aPrompt[nX + 1]
  255.                             nX = nX + 1
  256.                         enddo
  257.                     
  258.                         && Get prompt for additional record to be displayed
  259.                         aRec[nMaxRecs] = recno()
  260.                         cTemp = &cFields
  261.                         aPrompt[nMaxRecs] = substr(cTemp, 1, nPromptW)
  262.                         if len(aPrompt[nMaxRecs]) < nPromptW
  263.                             aPrompt[nMaxRecs] = aPrompt[nMaxRecs] + ;
  264.                                 space(nPromptW - len(aPrompt[nMaxRecs]))
  265.                         endif
  266.                         skip
  267.                     
  268.                         && Redisplay prompts with new contents
  269.                         nX = nMaxRecs
  270.                         do while nX > 0
  271.                             @ nTopRow + nX - 1, nLeftCol say aPrompt[nX]
  272.                             nX = nX - 1
  273.                         enddo
  274.                         nChcNum = nMaxRecs - 1
  275.                     endif
  276.                 
  277.                    nChcNum = iif(nChcNum < nHighChc, nChcNum + 1, 1)
  278.                    nRowOffset = iif(nChcNum = 1, 0, nChcNum - 1)
  279.                    nLastOne = iif(nChcNum = 1, nHighChc, nChcNum-1)
  280.                    nThisOne = nChcNum
  281.  
  282.                    @ nTopRow+iif(nChcNum = 1, nHighChc-1, nRowOffset-1) , ;
  283.                       nLeftCol say aPrompt[nLastOne]
  284.                    @ nTopRow+nRowOffset , nLeftCol get aPrompt[nThisOne]
  285.                    clear gets
  286.  
  287.                 case nKey = 13   && Enter key
  288.                     && Move record pointer and go back to calling program
  289.                     go aRec[nChcNum]
  290.                     lGoBack = .T.
  291.                     exit
  292.  
  293.                 case nKey = 3    && PgDn key
  294.                 
  295.                     && If last record in .DBF is displayed but not highlighted,
  296.                     && move highlight to bottom and wait for next key 
  297.                     if eof() .and. nChcNum # nHighChc
  298.                   @ nTopRow + nRowOffset, nLeftCol say aPrompt[nChcNum]
  299.                         @ nTopRow + nHighChc - 1, nLeftCol get aPrompt[nHighChc]
  300.                         clear gets
  301.                         nChcNum = nHighChc
  302.                   nRowOffset = nChcNum - 1
  303.                         loop
  304.                     endif
  305.                 
  306.                     && If highlight is not on last record that is displayed,
  307.                     && move highlight to it and wait for next key
  308.                     if nChcNum # nHighChc
  309.                   @ nTopRow + nRowOffset, nLeftCol say aPrompt[nChcNum]
  310.                         @ nTopRow + nHighChc - 1, nLeftCol get aPrompt[nHighChc]
  311.                         clear gets
  312.                         nChcNum = nHighChc
  313.                   nRowOffset = nChcNum - 1
  314.                   loop
  315.                     endif
  316.                 
  317.                     && Highlight is at bottom record displayed but not at eof
  318.                     && Move record pointer down to next "page" of records and
  319.                     && return to main loop
  320.                     if .not. eof()
  321.                         go aRec[1]
  322.                         skip + nMaxRecs
  323.                         lGoBack = .F.
  324.                         exit
  325.                     endif
  326.                 
  327.                     && If none of the above is true, wait for another key
  328.                     loop
  329.  
  330.                 case nKey = 18    && PgUp key
  331.                 
  332.                     && If top record displayed is top of .DBF but it is
  333.                     && not highlighted, move highlight to it and wait for next key
  334.                     if aRec[1] = nTopRec .and. nChcNum # 1
  335.                    @ nTopRow + nRowOffset, nLeftCol say aPrompt[nChcNum]
  336.                         @ nTopRow, nLeftCol get aPrompt[1]
  337.                         clear gets
  338.                         nChcNum = 1
  339.                   nRowOffset = 0
  340.                   loop
  341.                     endif
  342.                 
  343.                     && If highlight is not on top record displayed, move 
  344.                     && highlight to it and wait for next key
  345.                     if nChcNum # 1
  346.                   @ nTopRow + nRowOffset, nLeftCol say aPrompt[nChcNum]
  347.                         @ nTopRow, nLeftCol get aPrompt[1]
  348.                         clear gets
  349.                         nChcNum = 1
  350.                   nRowOffset = 0
  351.                         loop
  352.                     endif
  353.                 
  354.                     && Highlight is at top record displayed but not at top of DBF.
  355.                     && Move record pointer up one "page" worth of records and 
  356.                     && return to main loop to display new prompts
  357.                     if aRec[1] # nTopRec
  358.                         go aRec[1]
  359.                         skip - nMaxRecs
  360.                         lGoBack = .F.
  361.                         exit
  362.                     endif
  363.                 
  364.                     && If none of the above is true, wait for next key
  365.                     loop
  366.                 
  367.                 case nKey = 27   && Esc key
  368.                     && Move record pointer to where it was before starting this
  369.                     && routine and return to calling program
  370.                     lAbandon = .T.
  371.                     lGoBack = .T.
  372.                     go nTmpRec
  373.                     exit
  374.  
  375.                 case nKey = 26    && Home key
  376.                 
  377.                     && If already at top of DBF, wait for next key
  378.                     if aRec[1] = nTopRec
  379.                     loop
  380.                  else && go top and return to main loop to display new prompts
  381.                         go top
  382.                         lGoBack = .F.
  383.                         exit
  384.                     endif
  385.  
  386.                 case nKey = 2    && End key
  387.             
  388.                     && If last record in DBF is displayed but not highlighted,
  389.                     && move highlight to it and wait for next key
  390.                     if eof() .and. nChcNum # nHighChc
  391.                   @ nTopRow + nRowOffset, nLeftCol say aPrompt[nChcNum]
  392.                         @ nTopRow + nHighChc - 1, nLeftCol get aPrompt[nHighChc]
  393.                         clear gets
  394.                         nChcNum = nHighChc
  395.                   nRowOffset = nChcNum - 1
  396.                        loop
  397.                     endif
  398.                 
  399.                     && If last record is not displayed, go to it and 
  400.                     &&    return to main loop
  401.                     if .not. eof()
  402.                         go BOTtoM
  403.                         skip - (nMaxRecs - 1)
  404.                         lGoBack = .F.
  405.                         exit
  406.                     endif
  407.                 
  408.                     && If none of the above is true, go back and wait for next key
  409.                     loop
  410.  
  411.                 case nKey = 28  && F1 key
  412.                     && This is just sample code for the F1 key
  413.                     define window TempWin from 5,4 to 14,75
  414.                     activate window TempWin
  415.                     @ 1,3 say "Use cursor keys to choose. Press <Enter> to move record pointer"
  416.                     @ 2,5 say "Use <PgUp>, <PgDn>, <Home>, and <End> to see other records"
  417.                     @ 3,26 say "Use <Esc> to abandon"
  418.                     @ 5,23 say "Press Any Key to Continue"
  419.                     nX = 0
  420.                     do while nX = 0
  421.                         nX = inkey()
  422.                     enddo
  423.                     deactivate window TempWin
  424.             
  425.                 case nKey = -1  && F2 key
  426.                     && This is just sample code for the F2 key
  427.                     save screen to sScreen
  428.                     nX = recno()
  429.                     go aRec[nChcNum]
  430.                     set cursor ON
  431.                 edit nomenu noappend nodelete next 1
  432.                     * READ is better if you already have a FORMat set.
  433.                set cursor off
  434.                go aRec[nChcNum]
  435.                cTemp = &cFields  && Expands cFields into string expression
  436.                     aPrompt[nChcNum] = substr(cTemp, 1, nPromptW)
  437.                     if len(aPrompt[nChcNum]) < nPromptW
  438.                         aPrompt[nChcNum] = aPrompt[nChcNum] + ;
  439.                         space(nPromptW - len(aPrompt[nChcNum]))
  440.                     endif
  441.                restore screen from sScreen
  442.                     @ nTopRow+nRowOffset, nLeftCol get aPrompt[nChcNum]
  443.                clear gets
  444.                if nX <= reccount()
  445.                         go nX
  446.                     else
  447.                         go bott
  448.                         skip
  449.                     endif
  450.             endcase
  451.         enddo
  452.     enddo
  453.  
  454.     && Put colors back to what they were and set CURSOR, escape, and TALK back
  455.     set color of normal to &cNormSet
  456.     set color of fields to &cFieldset
  457.     set cursor &cCursor
  458.     set escape &cEscape
  459.     set talk &cTalk
  460.     
  461. RETURN
  462. *-- EOP: PickList
  463.